package org.rsbot.script.wrappers;

import java.lang.ref.SoftReference;
import org.rsbot.client.RSNPCDef;
import org.rsbot.script.methods.MethodContext;
import org.rsbot.script.methods.NPCs;
import org.rsbot.script.methods.Players;

public class RSNPC extends RSCharacter
{
  private final SoftReference<org.rsbot.client.RSNPC> npc;

  public RSNPC(MethodContext paramMethodContext, org.rsbot.client.RSNPC paramRSNPC)
  {
    super(paramMethodContext);
    this.npc = new SoftReference(paramRSNPC);
  }

  protected org.rsbot.client.RSCharacter getAccessor()
  {
    return (org.rsbot.client.RSCharacter)this.npc.get();
  }

  public String[] getActions() {
    RSNPCDef localRSNPCDef = getDefInternal();
    if (localRSNPCDef != null)
      return localRSNPCDef.getActions();
    return new String[0];
  }

  public int getID() {
    RSNPCDef localRSNPCDef = getDefInternal();
    if (localRSNPCDef != null)
      return localRSNPCDef.getType();
    return -1;
  }

  public String getName()
  {
    RSNPCDef localRSNPCDef = getDefInternal();
    if (localRSNPCDef != null)
      return localRSNPCDef.getName();
    return "";
  }

  public int getLevel()
  {
    RSNPCDef localRSNPCDef = getDefInternal();
    if (localRSNPCDef != null)
      return localRSNPCDef.getLevel();
    return -1;
  }

  public boolean isInteractingWithLocalPlayer()
  {
    RSNPC localRSNPC = this.methods.npcs.getNearest(new int[] { getID() });
    return localRSNPC.getInteracting() != null ? localRSNPC.getInteracting().equals(this.methods.players.getMyPlayer()) : false;
  }

  public String toString()
  {
    StringBuilder localStringBuilder = new StringBuilder();
    for (String str : getActions()) {
      localStringBuilder.append(str);
      localStringBuilder.append(",");
    }
    if (localStringBuilder.length() > 0) {
      localStringBuilder.setLength(localStringBuilder.length() - 1);
    }
    return new StringBuilder().append("NPC[").append(getName()).append("],actions=[").append(localStringBuilder.toString()).append("]").append(super.toString()).toString();
  }

  RSNPCDef getDefInternal()
  {
    org.rsbot.client.RSNPC localRSNPC = (org.rsbot.client.RSNPC)this.npc.get();
    if (localRSNPC == null) {
      return null;
    }
    return localRSNPC.getRSNPCDef();
  }
}